package com.ruoyi.finance.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.annotation.MyCache;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.finance.domain.vo.CredentialRollupVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.TVoucherDetail;
import com.ruoyi.finance.service.ITVoucherDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证明细Controller
 * 
 * @author ruoyi
 * @date 2025-02-26
 */
@Slf4j
@RestController
@RequestMapping("/Voucherdetail")
public class TVoucherDetailController extends BaseController
{
    @Autowired
    private ITVoucherDetailService tVoucherDetailService;

    @Resource
    RedisService redisService;

    /**
     * 查询凭证明细列表
     */
    @RequiresPermissions("finance:Voucherdetail:list")
    @GetMapping("/list")
    public TableDataInfo list(TVoucherDetail tVoucherDetail)
    {
        startPage();
        List<TVoucherDetail> list = tVoucherDetailService.selectTVoucherDetailList(tVoucherDetail);
        return getDataTable(list);
    }

    /**
     * 查询凭证汇总列表
     */
    @RequiresPermissions("finance:Voucherdetail:list")
    @GetMapping("/CredentialRollup")
//    @MyCache(cacheNames ="凭证汇总",key = "CredentialRollup")
    public AjaxResult CredentialRollup(CredentialRollupVo credentialRollupVo )
    {
        log.info("凭证汇总查询开始");
//        Integer pageNum = 1;
//        Integer pageSize = 10;

//        PageHelper.startPage(pageNum, pageSize);

        startPage();
        Map<String, Object> map = tVoucherDetailService.selectCredentialRollupList(credentialRollupVo);
//        redisService.setCacheList("CredentialRollup", list);
        return AjaxResult.success(map);
    }


    /**
     * 导出凭证明细列表
     */
    @RequiresPermissions("finance:Voucherdetail:export")
//    @Log(title = "凭证明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CredentialRollupVo credentialRollupVo) {
        tVoucherDetailService.export(response, credentialRollupVo);
    }
 

    /**
     * 获取凭证明细详细信息
     */
    @RequiresPermissions("finance:Voucherdetail:query")
    @GetMapping(value = "/{voucherDetailId}")
    public AjaxResult getInfo(@PathVariable("voucherDetailId") Long voucherDetailId)
    {
        return success(tVoucherDetailService.selectTVoucherDetailByVoucherDetailId(voucherDetailId));
    }

    /**
     * 新增凭证明细
     */
    @RequiresPermissions("finance:Voucherdetail:add")
    @Log(title = "凭证明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TVoucherDetail tVoucherDetail)
    {
        return toAjax(tVoucherDetailService.insertTVoucherDetail(tVoucherDetail));
    }

    /**
     * 修改凭证明细
     */
    @RequiresPermissions("finance:Voucherdetail:edit")
    @Log(title = "凭证明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TVoucherDetail tVoucherDetail)
    {
        return toAjax(tVoucherDetailService.updateTVoucherDetail(tVoucherDetail));
    }

    /**
     * 删除凭证明细
     */
    @RequiresPermissions("finance:Voucherdetail:remove")
    @Log(title = "凭证明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{voucherDetailIds}")
    public AjaxResult remove(@PathVariable Long[] voucherDetailIds)
    {
        return toAjax(tVoucherDetailService.deleteTVoucherDetailByVoucherDetailIds(voucherDetailIds));
    }
}
